class Solution {
    public int minOperations(int[] nums, int x) {
        int n = nums.length;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += nums[i];
        }
        sum -= x;
        if (sum < 0) return -1;
        int left = 0, right = 0;
        int len = -1;
        while (right < n) {
            sum -= nums[right];
            while (sum < 0) {
                sum += nums[left++];
            }
            if (sum == 0) {
                len = Math.max(len, right - left + 1);
            }
            right++;
        }
        if (len == -1) return -1;
        else return n - len;
    }

    public static void main(String[] args) {
        Solution s = new Solution();
        System.out.println(s.minOperations(new int[]{3, 2, 20, 1, 1, 3}, 10));
    }
}